home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 136_01.zip / TZ1.C < prev    next >
Text File  |  1993-06-01  |  23KB  |  1,176 lines

  1. /*    HEADER:  CUG136.20;
  2.     TITLE:        TZ;
  3.     VERSION:    0.29;
  4.     DATE:        3/12/1986;
  5.     DESCRIPTION:    "Twilight Zone Adventure Game (part 1)";
  6.     KEYWORDS:    game,adventure;
  7.     SYSTEM:        CP/M,MS-DOS,TOS;
  8.     FILENAME:    TZ1.C;
  9.     AUTHORS:    R. Rodman;
  10.     COMPILERS:    C/80,Aztec,Alcyon;
  11. */
  12.  
  13. /* TWILIGHT ZONE GAME
  14.  
  15.     TZ1.C - First half
  16.  
  17.     From 810717 (original assembler version) to 830125 in Z80 assembler.
  18.  
  19.     831025 rr begin conversion to C 0.10
  20.     831101 rr dictionary in room file 0.13
  21.     831104 rr add terminal file stuff 0.14
  22.     850412 rr mods for ibm 0.21
  23.     850429 rr for unbuf,use open returns int; for buf,use fopen
  24.             returns FILE (Aztec) 0.24
  25.     850430 rr try allocating buffer for Aztec 0.25
  26.     850521 rr try to fix messed-up message 0.27
  27.     860228 rr fix \n for cp/m 0.28
  28.     860311 rr split into two parts 0.29
  29.             add type to fopen
  30.     860312 rr st stuff
  31.  
  32. Version number is currently not displayed anywhere
  33.  
  34. NOTE:    The alloc() function does not work on the Atari ST.  To simplify
  35.     our lives, I don't use it.
  36.  
  37. The IBM switch is only known to work with the AZTEC compiler.
  38. */
  39.  
  40. /* #define IBM */    /* define this for IBM INT 10 screen control */
  41. #define TERMINAL    /* define this for TERMINAL.SYS */
  42.  
  43. /* #define AZTEC */    /* define this for Aztec C compiler */
  44. /* #define C80 */    /* define this for C/80 */
  45. #define DRI        /* define this for DRI C */
  46. #define ST        /* define this (and DRI?) for Atari ST */      
  47.  
  48. #ifdef C80
  49. #define DOS bdos
  50. #endif
  51.  
  52. #ifdef AZTEC
  53. #include "stdio.h"
  54. #include "fcntl.h"
  55. #define DOS bdos
  56. #endif
  57.  
  58. #ifdef DRI
  59. #include "stdio.h"
  60. #define DOS __BDOS
  61. #endif
  62.  
  63. #ifdef ST
  64. #include "osbind.h"
  65. #endif
  66.  
  67. #define BUFSIZE 30000
  68.  
  69. int cnt,i;
  70. char *room[ 256 ];            /* rooms */
  71. char *wlk_msg[ 24 ];            /* points to walker messages */
  72. char inp_buf[ 34 ];            /* input buffer */
  73. int inp_cnt = 0;            /* input buffer pointer */
  74.  
  75. #ifdef TERMINAL
  76.  
  77. #define BYTE char
  78. #define ESC '\033'
  79.  
  80. struct {                /* terminal file structure */    
  81.     BYTE width, height, defint, uselst, yfirst, method, addx, addy;
  82.     char inistr[ 8 ], clrscn[ 8 ], clreos[ 8 ], clreol[ 8 ];
  83.     char curoff[ 8 ], curon[ 8 ], curbeg[ 8 ], curmid[ 8 ];
  84.     char curend[ 8 ], hiint[ 8 ], loint[ 8 ], revvid[ 8 ];
  85.     char norvid[ 8 ], inslin[ 8 ], dellin[ 8 ];
  86. } trmbuf = {
  87. #ifdef ST
  88. /* Values for ST or Heath terminals */
  89.  
  90.     80, 24, 'H', 'Y', 'Y', '0', 32, 32,
  91.     0, 0, 0, 0, 0, 0, 0, 0,        /* inistr */
  92.     ESC, 'E', 0, 0, 0, 0, 0, 0,    /* clrscn */
  93.     ESC, 'J', 0, 0, 0, 0, 0, 0,    /* clreos */
  94.     ESC, 'K', 0, 0, 0, 0, 0, 0,    /* clreol */
  95.     ESC, 'x', '5', 0, 0, 0, 0, 0,    /* curoff */
  96.     ESC, 'y', '5', 0, 0, 0, 0, 0,    /* curon */
  97.     ESC, 'Y', 0, 0, 0, 0, 0, 0,    /* curbeg */
  98.     0, 0, 0, 0, 0, 0, 0, 0,        /* curmid */
  99.     0, 0, 0, 0, 0, 0, 0, 0,        /* curend */
  100.     0, 0, 0, 0, 0, 0, 0, 0,        /* hiint */
  101.     0, 0, 0, 0, 0, 0, 0, 0,        /* loint */
  102.     ESC, 'p', 0, 0, 0, 0, 0, 0,    /* revvid */
  103.     ESC, 'q', 0, 0, 0, 0, 0, 0,    /* norvid */
  104.     ESC, 'L', 0, 0, 0, 0, 0, 0,    /* inslin */
  105.     ESC, 'M', 0, 0, 0, 0, 0, 0    /* dellin */
  106. #endif
  107.  
  108. #ifndef ST
  109. /* Values for Televideoid terminals */
  110.  
  111.     80, 24, 'H', 'Y', 'Y', '0', 32, 32,
  112.     0, 0, 0, 0, 0, 0, 0, 0,        /* inistr */
  113.     '\032', 0, 0, 0, 0, 0, 0, 0,    /* clrscn */
  114.     ESC, 'Y', 0, 0, 0, 0, 0, 0,    /* clreos */
  115.     ESC, 'T', 0, 0, 0, 0, 0, 0,    /* clreol */
  116.     ESC, '.', '0', 0, 0, 0, 0, 0,    /* curoff */
  117.     ESC, '.', '2', 0, 0, 0, 0, 0,    /* curon */
  118.     ESC, '=', 0, 0, 0, 0, 0, 0,    /* curbeg */
  119.     0, 0, 0, 0, 0, 0, 0, 0,        /* curmid */
  120.     0, 0, 0, 0, 0, 0, 0, 0,        /* curend */
  121.     ESC, '(', 0, 0, 0, 0, 0, 0,    /* hiint */
  122.     ESC, ')', 0, 0, 0, 0, 0, 0,    /* loint */
  123.     ESC, 'G', '4', 0, 0, 0, 0, 0,    /* revvid */
  124.     ESC, 'G', '0', 0, 0, 0, 0, 0,    /* norvid */
  125.     ESC, 'R', 0, 0, 0, 0, 0, 0,    /* inslin */
  126.     ESC, 'E', 0, 0, 0, 0, 0, 0    /* dellin */
  127. #endif
  128. };
  129.  
  130. #endif
  131.  
  132. #ifdef IBM
  133. struct {
  134.     int width, height;
  135. } trmbuf = {
  136.     80, 25
  137. };
  138. #endif
  139.  
  140. /* Dictionary: words should be strung together,separated by spaces.
  141.     Only the unique part should be included.Contained in first line
  142.     of TZ.R.Every word including the last one must be followed by spaces.
  143.     Incidentally,all lines of TZ.R should be terminated only by
  144.     line feeds.*/
  145.  
  146. char *dic_ptr;
  147.  
  148. /* Controls used in messages are:
  149.     *    clear screen
  150.     ^    position cursor to message line (causes CEOL)
  151.     \    carriage return/line feed (causes CEOL)
  152.     |    position cursor to user input line (HEIGHT-2)
  153.     _    include answer here (e.g._4)
  154. */
  155.  
  156. /* The following pieces of information must be saved */
  157.  
  158. int rm_num = 0;            /* room number */
  159. int seed;            /* random seed */
  160. int wtchct = 0;            /* tv watch count */
  161. int beerct = 0;            /* drink beer count */
  162. int cratct = 0;            /* open crate count */
  163. int pushct = 0;            /* push button count */
  164. int pushfl = 0;            /* push button error flag */
  165. int answer[ 5 ] = { 0,1,2,3,4 };    /* digits of answer */
  166.  
  167. struct walker {
  168.     int inrm;        /* in room flag */
  169.     int rsel;        /* room pointer */
  170.     int dsel;        /* description selector */
  171.     int locn[ 8 ];        /* rooms walker appears at */
  172. };
  173.  
  174. /* Woman walker descriptor */
  175.  
  176. struct walker woman = {
  177.     0,0,0,
  178.     4,52,64,95,109,185,204,248 };
  179.  
  180. /* Man walker descriptor */
  181.  
  182. struct walker man = {
  183.     0,0,0,
  184.     3,49,97,105,111,144,166,175 };
  185.  
  186. /* Rod walker descriptor */
  187.  
  188. struct walker rod = {
  189.     0,0,0,
  190.     1,27,61,120,165,196,180,254 };
  191.  
  192. /* The following are not saved */
  193.  
  194. int nu_fl = 1;            /* new room flag */
  195. int curcol = 0;            /* cursor column */
  196.  
  197. int noun, verb;            /* word numbers */
  198.  
  199. char databuf[ BUFSIZE ];    /* statically allocated buffer */
  200.  
  201. extern hello();
  202. extern exbed(), pool(), echh(), busy(), call7(), call11(), sign(), book();
  203. extern opsafe(), dlcomb(), paper(), form(), blot(), seeslf(), seecow();
  204. extern mirhse(), menu(), drwatr(), excrat(), opcrat(), writing();
  205. extern inst(), buyber(), drbeer(), ridhor(), taktrn(), taknot(), plates();
  206. extern opgrat(), examtv(), wtchtv(), exhand(), push();
  207.  
  208. char xgetc();
  209.  
  210. /* Main Program */
  211.  
  212. main()
  213. {
  214.     int junk;
  215.  
  216.     term_init();        /* init terminal */
  217.  
  218.     hello();
  219.  
  220. /* initialize data */
  221.  
  222.     init_data();
  223.  
  224.     xputs( "\n\n?Dimensions out of range at address 1423" );
  225.  
  226.     junk = 0;
  227.     seed = 719;
  228.  
  229.     while( junk == 0 ) {
  230.         junk = xgetc();
  231.         seed = seed * 13;
  232.     }
  233.  
  234. /* synthesize solution from random number into answer[ 0..4 ] */
  235.  
  236.     if( seed < 0 ) seed = 0 - seed;        /* get abs value */ 
  237.  
  238.     answer[ 0 ] = seed % 5;
  239.     answer[ 1 ] = ( seed / 5 ) % 5;
  240.     answer[ 2 ] = ( seed / 25 ) % 5;
  241.     answer[ 3 ] = ( seed / 125 ) % 5;
  242.     answer[ 4 ] = ( seed / 625 ) % 5;
  243.  
  244.     while( 1 ) {
  245.         game();        /* process game */
  246.         input();    /* get input */
  247.     }
  248. }
  249.  
  250. #ifdef TERMINAL
  251.  
  252. /* --------TERMINAL FILE LOGIC-------- */
  253.  
  254. term_init()
  255. {
  256.     int t;
  257.  
  258. #ifdef C80
  259.     t = fopen( "TERMINAL.SYS","r" );
  260. #endif
  261.  
  262. #ifdef AZTEC
  263.     t = open( "TERMINAL.SYS", O_RDONLY );
  264. #endif
  265.  
  266. #ifdef DRI
  267.     t = open( "TERMINAL.SYS", 0 );
  268. #endif
  269.  
  270.     if( t == 0 ) return;    /* default to televideoid */
  271.  
  272.     read( t, &trmbuf, 128 );
  273.  
  274. #ifdef C80
  275.     fclose( t );
  276. #endif
  277.  
  278. #ifdef AZTEC
  279.     close( t );
  280. #endif
  281.  
  282. #ifdef DRI
  283.     close( t );
  284. #endif     
  285.  
  286. }
  287.  
  288. /* output a coordinate */
  289.  
  290. coord( c )
  291. int c;
  292. {
  293.     switch( trmbuf.method ) {
  294.     case 0 :
  295.     case '0' :
  296.     case 'B' :            /* binary positioning */
  297.         xputc( c ); break;
  298.     case 1 :
  299.     case '1' :
  300.     case 'A' :            /* ascii positioning */
  301.         if( c >= 100 ) {
  302.             xputc( '0' + c / 100 );
  303.             c %= 100;
  304.         }
  305.         if( c >= 10 ) {
  306.             xputc( '0' + c / 10 );
  307.             c %= 10;
  308.         }
  309.         xputc( '0' + c );
  310.     }
  311. }
  312.  
  313. /* position cursor */
  314.  
  315. goxy( x, y )
  316. int x, y;
  317. {
  318.     xputs( trmbuf.curbeg );
  319.     if( trmbuf.yfirst == 'Y' ) coord( y + trmbuf.addy );
  320.         else coord( x + trmbuf.addx );
  321.     xputs( trmbuf.curmid );
  322.     if( trmbuf.yfirst == 'Y' ) coord( x + trmbuf.addx );
  323.         else coord( y + trmbuf.addy );
  324.     xputs( trmbuf.curend );
  325. }
  326.  
  327. cls()
  328. {
  329.     xputs( trmbuf.clrscn );
  330. }
  331.  
  332. ceol()
  333. {
  334.     xputs( trmbuf.clreol );
  335. }
  336.  
  337. high()
  338. {
  339.     xputs( trmbuf.hiint );
  340. }
  341.  
  342. low()
  343. {
  344.     xputs( trmbuf.loint );
  345. }
  346.  
  347. reverse()
  348. {
  349.     xputs( trmbuf.revvid );
  350. }
  351.  
  352. normal()
  353. {
  354.     xputs( trmbuf.norvid );
  355. }
  356.  
  357. #endif        /* --------END OF TERMINAL FILE LOGIC-------- */
  358.  
  359. #ifdef IBM
  360.  
  361. /* --------IBM SCREEN LOGIC-------- */
  362.  
  363. term_init()
  364. {
  365. }
  366.  
  367. cls()
  368. {
  369.  
  370. #asm
  371.     mov    ah,0    ;subfunction - set display mode
  372.     mov    al,2    ;set mode to 80x25 bw
  373.     int    10H
  374. #endasm
  375.  
  376. }
  377.  
  378. goxy( x,y )
  379. int x,y;
  380. {
  381.  
  382. #asm
  383.     mov    ax,word ptr 8[bp]    ;get first parameter - x
  384.     mov    dl,al        ;put in dl
  385.  
  386.     mov    ax,word ptr 10[bp]    ;get second parameter - y
  387.     mov    dh,al        ;put in dh
  388.  
  389.     mov    ah,2
  390.     mov    al,0
  391.     mov    bh,0
  392.     int    10H
  393. #endasm
  394.  
  395. }
  396.  
  397. ceol()
  398. {
  399.     int i;
  400.     for( i = 0; i < ( trmbuf.width - 1 ); ++i ) xputc( ' ' );
  401.     xputc( '\r' );        /* return to left position */
  402. }
  403.  
  404. high()
  405. {
  406. }
  407.  
  408. low()
  409. {
  410. }
  411.  
  412. reverse()
  413. {
  414. }
  415.  
  416. normal()
  417. {
  418. }
  419.  
  420. #endif        /* --------END OF IBM SCREEN LOGIC-------- */
  421.  
  422. /* init room list and other data */
  423.  
  424. init_data()
  425. {
  426.     int rc;
  427.     char *p;
  428.  
  429. #ifdef C80    
  430.     rc = fopen( "TZ.R","r" );
  431.     if( rc == 0 ) {
  432.         xputs( "File not found." );
  433.         exit( 1 );
  434.     }
  435. #endif
  436.  
  437. #ifdef AZTEC     
  438.     rc = open( "TZ.R", O_RDONLY );
  439.     if( rc == -1 ) {
  440.         xputs( "File not found." );
  441.         exit( 1 );
  442.     }
  443. #endif
  444.  
  445. #ifdef DRI
  446.     rc = openb( "TZ.R", 0 );
  447.     if( rc == -1 ) {
  448.         xputs( "File not found." );
  449.         exit( 1 );
  450.     }
  451. #endif
  452.  
  453.     p = &databuf[ 0 ];        /* buffer for room data */
  454.  
  455. /* read entire file into buffer */
  456.  
  457.     cnt = read( rc, p, BUFSIZE );
  458.  
  459. #ifdef C80
  460.     fclose( rc );
  461. #endif
  462.  
  463. #ifdef AZTEC
  464.     close( rc );
  465. #endif
  466.  
  467. #ifdef DRI
  468.     close( rc );
  469. #endif
  470.  
  471. /* dictionary is first line of file */
  472.  
  473.     dic_ptr = p;
  474.  
  475. /* now look up indices to each string */
  476.  
  477.     for( i = 0; i < 256; i++ ) {
  478.         while( *p != '\012' ) p++;    /* find newline */
  479.         *p++ = '\0';            /* change to end of string */
  480.         room[ i ] = p;            /* assign pointer */
  481.     }
  482.     for( i = 0; i < 24; i++ ) {
  483.         while( *p != '\012' ) p++;    /* find newline */
  484.         *p++ = '\0';            /* change to end of string */
  485.         wlk_msg[ i ] = p;        /* assign pointer */
  486.     }
  487. }
  488.  
  489. /* Print Message */
  490.  
  491. print( m )
  492. char *m;
  493. {
  494.     char c;
  495.     char *k;
  496.     int j;
  497.  
  498.     while( *m ) {
  499.         c = *m++;
  500.  
  501.         switch( c ) {
  502.  
  503. /* Special handling for Space.
  504.     See if next word will fit on this line.*/
  505.  
  506.             case ' ' : j = curcol;
  507.                 k = m;        /* temp pointer */
  508.  
  509.                 while( j < ( trmbuf.width - 1 ) &&
  510.                     *k != ' '
  511.                     && *k != '\\'
  512.                     && *k != '.'
  513.                     && *k != ','
  514.                     && *k != '\0' ) {
  515.                     k++;
  516.                     j++;
  517.                 }
  518.  
  519.                 if( j < ( trmbuf.width - 1 )) {
  520.                     xputc( ' ' );
  521.                     curcol++;
  522.                 } else {
  523.                     xputc( '\n' );
  524.                     ceol();
  525.                     curcol = 0;
  526.                 }
  527.  
  528.                 break;
  529.  
  530.             case '\\' :        /* go to next line */
  531.                 xputc( '\n' );
  532.                 ceol();
  533.                 curcol = 0;
  534.                 break;
  535.  
  536.             case '*' :        /* clear screen */
  537.                 cls();
  538.                 high();    
  539.                 curcol = 0;
  540.                 break;
  541.  
  542.             case '^' :        /* user line */
  543.                 goxy( 0, trmbuf.height / 2 - 1 );
  544.  
  545.                 for( j = 1; j <= trmbuf.height / 2; j++ ) {
  546.                     ceol();
  547.                     xputc( '\n' );
  548.                 }
  549.  
  550.                 goxy( 0, trmbuf.height / 2 - 1 );
  551.                 curcol = 0;
  552.                 break;
  553.  
  554.             case '~' :        /* input line */
  555.                 goxy( 0, trmbuf.height - 1 );
  556.  
  557.                 low();
  558.                 reverse();
  559.  
  560. /* clear by brute force to make line look nice */
  561.  
  562.                 for( j = 1; j < trmbuf.width - 2; j++ )
  563.                     xputc( ' ' );
  564.                 normal();
  565.  
  566.                 goxy( 1, trmbuf.height - 1 );
  567.                 low();
  568.                 reverse();
  569.  
  570.                 curcol = 0;    
  571.                 break;
  572.  
  573. /* answer clues are imbedded in text as _1 to _5 */
  574.  
  575.             case '_' :        /* insert color */
  576.                 c = *m++;    /* get next char */
  577.                 switch( answer[ ( c & 7 ) - 1 ] ) {
  578.                     case 0:    xputs( "red" );
  579.                         curcol += 3;
  580.                         break;  
  581.                     case 1: xputs( "orange" );
  582.                         curcol += 6;
  583.                         break;
  584.                     case 2: xputs( "yellow" );
  585.                         curcol += 6;
  586.                         break;
  587.                     case 3: xputs( "green" );
  588.                         curcol += 5;
  589.                         break;
  590.                     case 4: xputs( "blue" );
  591.                         curcol += 4;
  592.                         break;
  593.                 }
  594.                 break;
  595.  
  596.             case '.' :
  597.             case ',' :
  598.                 xputc( c );    /* print period */
  599.                 xputc( ' ' );
  600.                 if( c == '.' ) xputc( ' ' );    /* spaces */
  601.                 curcol += 3;
  602.                 break;
  603.  
  604.             default :
  605.                 xputc( c );
  606.                 curcol++;
  607.         }
  608.     }
  609.  
  610.     normal();
  611.     high();
  612. }
  613.  
  614. /* Main Game Process */
  615.  
  616. game()
  617. {
  618.     char *c;
  619.  
  620.     if( ! nu_fl ) return;    /* return if haven't moved into a new room */
  621.  
  622.     nu_fl = 0;            /* reset new room flag */
  623.  
  624.     c = room[ rm_num ];        /* get initial room pointer */
  625.     while( *c != '*' ) c++;        /* point to first asterisk */
  626.  
  627.     print( c );            /* print description */
  628.  
  629. /* just arrived in a new room.clear all in-room flags */
  630.  
  631.     woman.inrm = 0;
  632.     man.inrm = 0;
  633.     rod.inrm = 0;
  634.  
  635. /* check to see if walkers are in your room */
  636.  
  637.     if( woman.locn[ woman.rsel ] == rm_num ) {
  638.         print( wlk_msg[ woman.dsel ] );
  639.         woman.rsel = ++woman.rsel % 8;
  640.         if( woman.dsel < 7 ) woman.dsel++;
  641.         woman.inrm = 1;
  642.     }
  643.  
  644.     if( man.locn[ man.rsel ] == rm_num ) {
  645.         print( wlk_msg[ 8 + man.dsel ] );
  646.         man.rsel = ++man.rsel % 8;
  647.         if( man.dsel < 7 ) man.dsel++;
  648.         man.inrm = 1;
  649.     }
  650.  
  651.     if( rod.locn[ rod.rsel ] == rm_num ) {
  652.         print( wlk_msg[ 16 + rod.dsel ] );
  653.         rod.rsel = ++rod.rsel % 8;
  654.         if( rod.dsel < 7 ) rod.dsel++;
  655.         rod.inrm = 1;
  656.     }
  657.  
  658.     print( "~What do you do?" );
  659. }
  660.  
  661. /* Input Process */
  662.  
  663. input()
  664. {
  665.     char c;
  666.  
  667.     c = xgetc();
  668.  
  669.     if( c == 0 ) return;        /* quit if no input */
  670.  
  671.     goxy( inp_cnt + 22, trmbuf.height - 1 );
  672.  
  673.     switch( c ) {
  674.         case '\r' :
  675.             parse();        /* get command */
  676.             print( "~What do you do?" ); /* re-prompt */
  677.             inp_cnt = 0;
  678.             break;
  679.         case '\b' :
  680.             if( ! inp_cnt ) break;    /* backspace */
  681.             inp_cnt--;
  682.             xputs( "\b \b" );
  683.             break;
  684.  
  685.         default :
  686.             if( c < ' ' || inp_cnt > 30 ) break;
  687.             if( c >= 'A' && c <= 'Z' )
  688.                 c += 32;    /* convert lower */
  689.             xputc( c );        /* duplex */
  690.             inp_buf[ inp_cnt++ ] = c;
  691.     }
  692. }
  693.  
  694. /* Get word */
  695.  
  696. get_word( p )
  697. char *p;
  698. {
  699.     int k,match;
  700.     char *q,*d;
  701.  
  702.     if( ! *p ) return( 0 );
  703.  
  704.     k = 0;                    /* word counter */
  705.     d = dic_ptr;                /* index into dict */
  706.  
  707.     while( *d ) {
  708.         q = p;                /* point to begin of word */
  709.         match = 1;            /* pretend we have a match */
  710.  
  711.         k++;                /* count a word */ 
  712.  
  713.         while( *d != ' ' ) {        /* compare this word */
  714.             if( *q++ != *d++ ) match = 0;
  715.         }                /* d points to space */
  716.  
  717.         if( match ) return( k );    /* got a match */
  718.         d++;                /* skip the space */
  719.     }
  720.  
  721.     return( 0 );    /* came to end of dictionary */
  722. }
  723.  
  724. /* Parse Command */
  725.  
  726. parse()
  727. {
  728.     char *p_ptr;
  729.  
  730.     if( ! inp_cnt ) return;            /* empty line input */
  731.  
  732.     inp_buf[ ++inp_cnt ] = ' ';        /* add space to input */
  733.     inp_buf[ ++inp_cnt ] = '\0';        /* terminate it */
  734.  
  735.     noun = 0;
  736.     verb = 0;
  737.  
  738.     p_ptr = &inp_buf[ 0 ];            /* point to first word */
  739.  
  740.     verb = get_word( p_ptr );        /* get verb */
  741.  
  742.     while( *p_ptr != ' ' ) p_ptr++;        /* find blank */
  743.     while( *p_ptr == ' ' ) p_ptr++;        /* find non-blank */
  744.  
  745.     noun = get_word( p_ptr );        /* get noun if any */
  746.  
  747.     switch( verb ) {
  748.         case 7 : go( noun ); break;
  749.  
  750.         case 8 : if( noun == 29 && rm_num == 63 ) taktrn();
  751.                 else print( "^You can't take it with you." );
  752.             break;        
  753.  
  754.         case 9 : exit();    /* quit game */
  755.  
  756.         case 10 : if( noun == 11 ) {
  757.                 switch( rm_num ) {
  758.                     case 7 : call11(); break;
  759.                     case 11 : call7(); break;
  760.                     case 174 :
  761.                     case 222 :
  762.                     case 249 : busy(); break;
  763.                     default : cant();
  764.                 }
  765.             }
  766.             else cant();
  767.             break;
  768.         case 13 : switch( noun ) {
  769.             case 14 : menu( rm_num ); break;
  770.  
  771.             case 15 : if( rm_num == 7 || rm_num == 174
  772.                     || rm_num == 222 || rm_num == 249 )
  773.                     sign();
  774.                     else cant();
  775.                 break;
  776.  
  777.             case 16 : if( rm_num == 7 || rm_num == 174
  778.                     || rm_num == 222 || rm_num == 249 )
  779.                     book();
  780.                     else cant();
  781.                 break;
  782.  
  783.             case 17 : if( rm_num == 100 ) form();
  784.                 else cant();
  785.                 break;
  786.             case 24 : writing( rm_num ); break;
  787.  
  788.             case 25 : if( rm_num == 29 ) inst();
  789.                 else cant();
  790.                 break;
  791.  
  792.             case 39 : plates( rm_num ); break;
  793.  
  794.             case 42 : paper( rm_num ); break;
  795.  
  796.             default : cant(); break;
  797.             }
  798.             break;
  799.  
  800.         case 20 : if( noun == 21 && rm_num == 13 ) buyber();
  801.             else cant();
  802.             break;
  803.  
  804.         case 22 : switch( noun ) {
  805.                 case 18 : if( rm_num == 100 ) blot();
  806.                     else cant();
  807.                     break;
  808.                 case 41 : if( rm_num == 21 ) excrat();
  809.                     else cant();
  810.                     break;
  811.                 case 31 : if( rm_num == 163 ) examtv();
  812.                     else cant();
  813.                     break;
  814.                 case 23 : if( rm_num == 198 ) exhand();
  815.                     else cant();
  816.                     break;
  817.                 case 54 :
  818.                 case 49 : if( rm_num == 58 ) pool();
  819.                     else cant();
  820.                     break;
  821.                 case 57 : if( rm_num == 38 ||
  822.                         rm_num == 66 ||
  823.                         rm_num == 178 ) {
  824.                         exbed(); break;
  825.                     }
  826.                 default : print( "^Nothing unusual." );
  827.                     break;
  828.             }
  829.             break;
  830.  
  831.         case 30 : if( noun == 31 && rm_num == 163 ) wtchtv();
  832.                 else cant();
  833.                 break;
  834.         case 37 : if( rm_num == 128 ) push();
  835.                 else cant();
  836.                 break;
  837.         case 38 : switch( noun ) {        /* LOOK */
  838.                 case 12 : if( rm_num == 0 || rm_num == 66
  839.                         || rm_num == 106
  840.                         || rm_num == 178
  841.                         || rm_num == 255 ) {
  842.                         seeslf();
  843.                         break;
  844.                     }
  845.                     if( rm_num == 38 ) {
  846.                         seecow();
  847.                         break;
  848.                     }
  849.                     if( rm_num >= 223 && rm_num <= 231 ) {
  850.                         mirhse( rm_num );
  851.                         break;
  852.                     }
  853.                     cant();
  854.                     break;
  855.                 case 54 :
  856.                 case 49 : if( rm_num == 58 ) pool();
  857.                     else cant();
  858.                     break;
  859.                 default : nu_fl = 1; break;
  860.             }
  861.             break;        
  862.  
  863.         case 40 : switch( noun ) {
  864.                 case 41 : if( rm_num == 21 ) opcrat();
  865.                     else cant(); break;
  866.                 case 43 : if( rm_num == 152 ) opsafe();
  867.                     else cant(); break;
  868.                 case 52 : if( rm_num == 220 ) opgrat();
  869.                     else cant(); break;
  870.                 default : print( "^There's nothing to open." );
  871.                     break;
  872.             }
  873.             break;
  874.  
  875.         case 44 : if( noun == 45 && rm_num == 152 ) dlcomb();
  876.             else cant(); break;
  877.         case 46 : savgam(); break;
  878.         case 47 : lodgam(); break;
  879.  
  880.         case 48 : switch( noun ) {
  881.                 case 21 : if( rm_num == 13 ) drbeer();
  882.                     else cant();
  883.                     break;
  884.                 case 49 : if( rm_num == 9 || rm_num == 221 ) {
  885.                         drwatr();
  886.                         break;
  887.                     }
  888.                     if( rm_num == 58 ) echh();
  889.                     else cant();
  890.                     break;
  891.                 case 54 : if( rm_num == 58 ) echh();
  892.                     else cant();
  893.                     break;
  894.                 default : cant(); break;
  895.             }
  896.             break;
  897.  
  898.         case 50 : if( noun == 51 && rm_num == 14 ) ridhor();
  899.                 else cant();
  900.             break;
  901.         case 55 : say();        /* speak to walkers */
  902.             break;    
  903.  
  904. /* synonyms for go */
  905.  
  906.         case 64 : go( 1 ); break;
  907.         case 65 : go( 2 ); break;
  908.         case 66 : go( 3 ); break;
  909.         case 67 : go( 4 ); break;
  910.         case 68 : go( 5 ); break; 
  911.         case 69 : go( 6 ); break;
  912.         case 70 : go( 27 ); break;
  913.         case 71 : go( 28 ); break;
  914.         case 26 : go( 26 ); break;    /* sleep */
  915.  
  916.         case 72 : vahr(); break;    /* Vahr */    
  917.  
  918.         default : cant();
  919.     }
  920. }
  921.  
  922. vahr()
  923. {
  924.     char *p;
  925.  
  926.     p = &inp_buf[ 0 ];        /* point to begin of input buf */
  927.  
  928.     while( *p != ' ' ) ++p;        /* find end of first word */
  929.  
  930.     while( *p == ' ' ) ++p;        /* find begin of next word */
  931.  
  932.     if( *p++ != '#' ) cant();
  933.         else {
  934.             rm_num = convert( p );
  935.             nu_fl = 1;
  936.     }
  937. }
  938.         
  939. savgam()
  940. {
  941.     int i;
  942.  
  943. #ifdef C80
  944.     int fc;
  945.     fc = fopen( "TZ.SAV", "wb" );
  946. #endif
  947.  
  948. #ifdef AZTEC    
  949.     FILE *fc;
  950.     fc = fopen( "TZ.SAV","w" );
  951. #endif
  952.  
  953. #ifdef DRI    
  954.     FILE *fc, *fopen();
  955.     fc = fopen( "TZ.SAV","w" );
  956. #endif
  957.  
  958.     if( fc == 0 ) {
  959.         print( "^Can't create output file." );
  960.         return;
  961.     }
  962.  
  963.     putc( rm_num,fc );    /* write room number */
  964.     putc( seed % 256,fc );
  965.     putc( seed / 256,fc );    /* random seed */
  966.     putc( wtchct,fc );    /* tv watch count */
  967.     putc( beerct,fc );    /* drink beer count */
  968.     putc( cratct,fc );    /* open crate count */
  969.     putc( pushct,fc );    /* push button count */
  970.     putc( pushfl,fc );    /* push button error flag */
  971.  
  972.     for( i = 0; i < 5; i++ ) putc( answer[ i ],fc );
  973.                 /* digits of answer */
  974.  
  975.     putc( woman.inrm,fc );
  976.     putc( woman.rsel,fc );
  977.     putc( woman.dsel,fc );
  978.  
  979.     putc( man.inrm,fc );
  980.     putc( man.rsel,fc );
  981.     putc( man.dsel,fc );
  982.  
  983.     putc( rod.inrm,fc );
  984.     putc( rod.rsel,fc );
  985.     putc( rod.dsel,fc );
  986.  
  987.     fclose( fc );
  988.  
  989.     print( "^Game has been saved." );
  990. }
  991.  
  992. lodgam()
  993. {
  994.     int i;
  995.  
  996. #ifdef C80
  997.     int fc;
  998.     fc = fopen( "TZ.SAV", "rb" );
  999. #endif
  1000.  
  1001. #ifdef AZTEC    
  1002.     FILE *fc;
  1003.     fc = fopen( "TZ.SAV", "r" );
  1004. #endif
  1005.  
  1006. #ifdef DRI    
  1007.     FILE *fc, *fopen();
  1008.     fc = fopen( "TZ.SAV", "r" );
  1009. #endif
  1010.  
  1011.     if( fc == 0 ) {
  1012.         print( "^Can't open input file." );
  1013.         return;
  1014.     }
  1015.  
  1016.     rm_num = getc( fc );        /* write room number */
  1017.     seed = getc( fc );
  1018.     seed += 256 * getc( fc );    /* random seed */
  1019.     wtchct = getc( fc );        /* tv watch count */
  1020.     beerct = getc( fc );        /* drink beer count */
  1021.     cratct = getc( fc );        /* open crate count */
  1022.     pushct = getc( fc );        /* push button count */
  1023.     pushfl = getc( fc );        /* push button error flag */
  1024.  
  1025.     for( i = 0; i < 5; i++ ) answer[ i ] = getc( fc );
  1026.                 /* digits of answer */
  1027.  
  1028.     woman.inrm = getc( fc );
  1029.     woman.rsel = getc( fc );
  1030.     woman.dsel = getc( fc );
  1031.  
  1032.     man.inrm = getc( fc );
  1033.     man.rsel = getc( fc );
  1034.     man.dsel = getc( fc );
  1035.  
  1036.     rod.inrm = getc( fc );
  1037.     rod.rsel = getc( fc );
  1038.     rod.dsel = getc( fc );
  1039.  
  1040.     fclose( fc );
  1041.  
  1042.     nu_fl = 1;            /* flag new room */
  1043. }
  1044.  
  1045. /* Go Routine */
  1046.  
  1047. go( n )
  1048. int n;
  1049. {
  1050.     char dirc,*c;
  1051.  
  1052.     switch( n ) {
  1053.         case 1 : dirc = 'n'; break;    /* get direction character */
  1054.         case 2 : dirc = 's'; break;
  1055.         case 3 : dirc = 'e'; break;
  1056.         case 4 : dirc = 'w'; break;
  1057.         case 5 : dirc = 'u'; break;
  1058.         case 6 : dirc = 'd'; break;
  1059.         case 27 : dirc = 'i'; break;
  1060.         case 28 : dirc = 'o'; break;
  1061.         case 19 : dirc = 'b'; break;    /* below */
  1062.         case 26 : dirc = 'z'; break;    /* sleep */
  1063.         default : dirc = '?'; break;
  1064.     }
  1065.  
  1066.     c = room[ rm_num ];        /* get pointer to room */
  1067.  
  1068.     while( *c != '*' ) {
  1069.         if( *c++ == dirc ) {
  1070.             rm_num = convert( c );
  1071.             nu_fl = 1;    /* inform game() */
  1072.             return;
  1073.         }
  1074.     }
  1075.  
  1076. /* fell through,direc must be bad */
  1077.  
  1078.     print( "^You can't go that way." );
  1079. }
  1080.  
  1081. int convert( c )
  1082. char *c;
  1083. {
  1084.     int r;
  1085.  
  1086.     r = 0;
  1087.  
  1088.     while( *c >= '0' && *c <= '9' )
  1089.         r = 10 * r + *c++ - '0';
  1090.  
  1091.     return( r );
  1092. }
  1093.  
  1094. /* Simply Cannot Do Something */
  1095.  
  1096. cant()
  1097. {
  1098.     print( "^You cannot do that here." );
  1099. }
  1100.  
  1101. /* Speak to the Walkers */
  1102.  
  1103. say()
  1104. {
  1105.     if( woman.inrm ) {
  1106.         switch( noun ) {
  1107.             case 56 :
  1108.     print( "^'Hi,' she smiles back.'Have you found anything?'" );
  1109.                 break;
  1110.             case 45 : print( "*Aileen has shot you." );
  1111.                 exit( 0 );
  1112.             default :
  1113.     print( "^The woman gives you a puzzled look." );
  1114.     print( " 'What are you trying to say?'" );
  1115.         }
  1116.         return;
  1117.     }
  1118.  
  1119.     if( man.inrm ) {
  1120. print( "^You'd like to talk to him,sure,but he's already gone." );
  1121.         return;
  1122.     }
  1123.  
  1124.     if( rod.inrm ) {
  1125. print( "^The man in the dark suit pays no attention to anything you say." );
  1126.         return;
  1127.     }
  1128.  
  1129.     print( "^There is no one here to speak to." );
  1130. }
  1131.  
  1132. /* raw output of string */
  1133.  
  1134. xputs( c )
  1135. char *c;
  1136. {
  1137.     while( *c ) xputc( *c++ );
  1138. }
  1139.  
  1140. /* sample keyboard, return 0 if no char avail */
  1141.  
  1142. char xgetc()
  1143. {
  1144. #ifdef ST
  1145.     if( Bconstat( 2 ) != 0 ) return( Bconin( 2 ) & 0xFF );
  1146.         else return 0;
  1147. #endif
  1148.  
  1149. #ifndef ST
  1150.     return( DOS( 6, 0xFF ));
  1151. #endif
  1152. }
  1153.  
  1154. /* Raw output of a character */
  1155.  
  1156. xputc( c )
  1157. char c;
  1158. {
  1159.     if( c == '\n' ) xputc( '\r' );
  1160. #ifdef ST
  1161.     Bconout( 2, c );
  1162. #endif
  1163.  
  1164. #ifndef ST
  1165.     DOS( 6, c );
  1166. #endif
  1167. }
  1168.  
  1169. #ifdef C80
  1170. #include "stdlib.c"
  1171. #endif
  1172.  
  1173. /* end of tz1.c */
  1174.  
  1175.  
  1176.